package APP3.bookshop.main;

import APP3.bookshop.book.ABook;
import APP3.bookshop.book.ElectronicBook;
import APP3.bookshop.book.PaperBook;
import APP3.bookshop.main.*;
import APP3.bookshop.gui.*;
import APP3.bookshop.order.Order;
import APP3.bookshop.person.author.Author;
import APP3.bookshop.person.publisher.Publisher;
import APP3.services.AuthorService;
import APP3.services.BookManager;
import APP3.services.OrderService;
import APP3.services.PublisherService;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 *
 * @author Asus
 */
public class BookShop {

    //gui
    private MainFrame GUI;

    private List<ABook> library;
    private List<Author> authors;
    List<Publisher> publishers;
    private List<Order> orders;

    BookManager bookmanager;
    AuthorService authorservice;
    PublisherService pubService;
    OrderService orderService;

    public BookShop() {
        createDateStructures();
        putRandomData();
        createServices();

        startGUI();

    }

    public MainFrame getGUI() {
        return GUI;
    }

    public List<ABook> getLibrary() {
        return library;
    }

    public List<Publisher> getPublishers() {
        return publishers;
    }

    private void startGUI() {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                GUI = new MainFrame(BookShop.this);
                GUI.pack();
                GUI.setVisible(true);
            }
        });

    }

    public static void main(String[] args) {
        BookShop bookshop;
        bookshop = new BookShop();
    }

    private void createServices() {
        this.bookmanager = new BookManager(this);
        this.authorservice = new AuthorService(this);
        this.pubService = new PublisherService(this);
        this.orderService = new OrderService(this);
    }

    public BookManager getBookmanager() {
        return bookmanager;
    }

    private void createDateStructures() {
        library = new ArrayList<ABook>();
        authors = new ArrayList<Author>();
        publishers = new ArrayList<Publisher>();
        orders = new ArrayList<Order>();
    }

    private void putRandomData() {
        for (int i = 0; i < 10; i++) {
            Publisher pub = new Publisher();
            pub.setName("pub" + i);

            Author a = new Author();
            a.setName("author " + i);

            //ElectronicBook book = new ElectronicBook("code+i","book" + i, new Date(), pub);
            PaperBook book = new PaperBook("title"+i, new Date(), pub);
            book.setAuthor(a);
            book.setPublisher(pub);
            library.add(book);
            publishers.add(pub);
            authors.add(a);
        }

        for (int i = 0; i < 10; i++) {
            Order o = new Order();
            o.setOrderDate(new Date());
            o.setDeliveryDate(new Date());
            o.setPublisher(publishers.get(i));
            o.getaBookCopies().put(library.get(i), i);
            orders.add(o);
        }

    }

    public List<Author> getAuthors() {
        return authors;
    }

    public AuthorService getAuthorservice() {
        return authorservice;
    }

    public PublisherService getPublisherService() {
        return pubService;
    }

    public PublisherService getPubService() {
        return pubService;
    }

    public OrderService getOrderService() {
        return orderService;
    }

    public List<Order> getOrders() {
        return orders;
    }

}
